﻿using System.Web.Optimization;
using RS.Web;
using RS.Web.Globalization;
using TimeManagementMobile.BundleTransforms;
using TimeManagementMobile.Resources;

namespace TimeManagementMobile
{
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            foreach (string liso in CultureHelper.ValidCultures)
            {
                ScriptBundle bundle = CreateScriptBundle(liso);
                bundles.Add(bundle);
            }

            bundles.Add(AddStyleBundle("~/Content/themes/base/css", null,
                "~/Content/themes/base/reset.css",
                "~/Content/themes/base/roboto.css",
                "~/Content/themes/base/tmm.css",
                "~/Content/themes/base/mobiscroll-2.0.custom.min.css",
                "~/Content/themes/base/general.css",
                "~/Content/themes/base/autentificare-companii.css",
                "~/Content/themes/base/autentificare-login.css",
                "~/Content/themes/base/elements.css",
                "~/Content/themes/base/lista-angajati.css",
                "~/Content/themes/base/lista-notificari.css",
                "~/Content/themes/base/cereri-concediu.css",
                "~/Content/themes/base/mainmeniu.css",
                "~/Content/themes/base/my-profile.css",
                "~/Content/themes/base/setari.css",
                "~/Content/themes/base/dashboard.css",
                "~/Content/themes/base/nointernet.css"
                ));
        }

        private static ScriptBundle CreateScriptBundle(string liso)
        {
            ScriptBundle mainBundle = AddScriptBundle("~/bundles/all/" + liso, null,
                "~/Scripts/jquery-{version}.js",
                "~/Scripts/handlebars.js",
                "~/Scripts/helpers.js",
                "~/Scripts/json2.js",
                "~/Scripts/jstorage.js",
                "~/Scripts/moment.js",
                "~/Scripts/tap.js",
                "~/Scripts/mobiscroll-2.0.custom.min.js",
                "~/Scripts/jquery.pull-to-refresh.js",
                "~/Scripts/jquery.autogrowtextarea.js",
                "~/Scripts/flipable.js",
                "~/Scripts/Application/Controls/dialog.js",
                "~/Scripts/Application/Controls/CereriConcediiFilter.js",
                "~/Scripts/Application/Controls/EmployeesFilter.js",
                "~/Scripts/Application/Controls/LeftMenu.js",
                "~/Scripts/Application/Controls/NotificationsManager.js",
                "~/Scripts/Application/Controls/SearchBar.js",
                "~/Scripts/Application/Controls/SearchResultsInfo.js",
                "~/Scripts/Application/Controls/SituatieCO.js",
                "~/Scripts/Application/RS.js",
                "~/Scripts/Application/RS.Global.js",
                "~/Scripts/Application/Core.js",
                "~/Scripts/Application/Event.js",
                "~/Scripts/Application/TMM.Global.js",
                "~/Scripts/Application/Extensions.js",
                "~/Scripts/Application/Keys.js",
                "~/Scripts/Application/MessagesFactory.js",
                "~/Scripts/Application/Misc.js",
                "~/Scripts/Application/Constants.js",
                "~/Scripts/Application/Application.js",
                "~/Scripts/Application/MobileApplication.js",
                "~/Scripts/Application/Page.js",
                "~/Scripts/Application/MobilePage.js",
                "~/Scripts/Application/PhoneCommunicator.js",
                "~/Scripts/Application/Time.js",
                "~/Scripts/Application/TMMobilePage.js",
                "~/Scripts/Application/TMMobile.js",
                "~/Scripts/Application/Utils.js",
                "~/Scripts/Application/Loader.js",
                "~/Scripts/Application/General.js",
                "~/Scripts/Application/tappable.js",
                "~/Scripts/Application/tmmService.js",
                "~/Scripts/Application/Modules/Authentication/AuthenticationPage.js",
                "~/Scripts/Application/Modules/Authentication/CompanyConnectionPage.js",
                "~/Scripts/Application/Modules/CentreCost/CentreCostPage.js",
                "~/Scripts/Application/Modules/CereriConcedii/Filtru/SelectareDepartamentPage.js",
                "~/Scripts/Application/Modules/CereriConcedii/Filtru/SelectareFunctiePage.js",
                "~/Scripts/Application/Modules/CereriConcedii/Filtru/SelectarePunctDeLucruPage.js",
                "~/Scripts/Application/Modules/CereriConcedii/Filtru/SelectareStatusConcediuPage.js",
                "~/Scripts/Application/Modules/CereriConcedii/Filtru/SelectareSubtipConcediuPage.js",
                "~/Scripts/Application/Modules/CereriConcedii/Filtru/SelectareTipConcediuPage.js",
                "~/Scripts/Application/Modules/CereriConcedii/CererePage.js",
                "~/Scripts/Application/Modules/CereriConcedii/CereriConcediiPage.js",
                "~/Scripts/Application/Modules/CereriConcedii/IstoricCererePage.js",
                "~/Scripts/Application/Modules/Dashboard/DashboardManager.js",
                "~/Scripts/Application/Modules/Dashboard/Dashboard.js",
                "~/Scripts/Application/Modules/Dimensiuni/SelectareDimensiuniPage.js",
                "~/Scripts/Application/Modules/Dimensiuni/SelectareDimensiuniStructuriPage.js",
                "~/Scripts/Application/Modules/EmployeesList/EmployeeInfoPage.js",
                "~/Scripts/Application/Modules/EmployeesList/EmployeesListPage.js",
                "~/Scripts/Application/Modules/Notifications/NotificationsPage.js",
                "~/Scripts/Application/Modules/User/ChangePasswordPage.js",
                "~/Scripts/Application/Modules/User/ChangePicture.js",
                "~/Scripts/Application/Modules/User/MyProfilePage.js",
                "~/Scripts/Application/Modules/User/SettingsPage.js"
                );

            new GlobalizationBundler(Static.ResourceManager).AddGlobalizationToBundle(mainBundle, liso);

            return mainBundle;
        }

        private static ScriptBundle AddScriptBundle(string virtualPath, IBundleTransform transform,
            params string[] virtualPaths)
        {
            var bundle = new ScriptBundle(virtualPath);

            if (virtualPaths != null)
                bundle.Include(virtualPaths);

            bundle.Transforms.Add(new CopyrightBundleTransform());

            if (transform != null)
                bundle.Transforms.Add(transform);

            return bundle;
        }

        private static StyleBundle AddStyleBundle(string virtualPath, IBundleTransform transform,
            params string[] virtualPaths)
        {
            var bundle = new StyleBundle(virtualPath);
            bundle.Include(virtualPaths);

            bundle.Transforms.Add(new CopyrightBundleTransform());

            if (transform != null)
                bundle.Transforms.Add(transform);

            return bundle;
        }
    }
}